import React from 'react'
import { Cart } from '@nutui/icons-react'
import { Ellipsis } from '@nutui/nutui-react';
import { useNavigate } from 'react-router-dom';
export default function GoodItem(props) {
    // 路由跳转传参 创建对象
    let nav=useNavigate()
    let {obj,addshopcar}=props
    let xiang=(obj)=>{
        // 进入详情页面，将obj传递过去
        nav('/xiang',{state:obj})
    }
    return (
        <div className='good_item' onClick={()=>{ xiang(obj)}}>
            <img src={obj.img} alt="" />
            <div className='good_info'>
                <p className='good_name'>{obj.name}&nbsp;{obj.specTitle}</p>
                {/* <p>{item.desc}</p> */}
                <Ellipsis content={obj.desc}
                    direction="end"
                    style={{ color: '#808080' }} />
                <div className='good_price_box'>
                    <p className='good_price'>￥{obj.price}</p>
                    <div className='good_cart'>
                        <Cart onClick={(event) => {
                            // 阻止冒泡
                            event.stopPropagation()
                            // 点击加入购物车，数量加一
                            obj.buyNum+=1
                            addshopcar(obj)
                        }} /><span className='add_num'>{obj.buyNum > 0 ? obj.buyNum : null}</span>
                    </div>
                </div>

            </div>
        </div>
    )
}
